import numpy as np  
from sklearn import datasets  
from sklearn.model_selection import train_test_split  
from sklearn.neighbors import KNeighborsClassifier 
iris = datasets.load_iris()
X_train, X_test, Y_train, Y_test = train_test_split(iris['data'], iris['target'], random_state=0)  
X_new = np.array([[5, 2.9, 1, 0.2]]) 
knn = KNeighborsClassifier()  
knn.fit(X_train, Y_train) 

prediction = knn.predict(X_new)  
print(prediction) 
print(iris['target_names'][prediction])  
y_pred = knn.predict(X_test)  
print('{:.2f}'.format(np.mean(y_pred == Y_test)))  
print('{:.2f}'.format(knn.score(X_test, Y_test))) 
